package com.karaoke.android.home.fragment


import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RadioGroup
import com.karaoke.android.home.R

/**
 * A simple [Fragment] subclass.
 */
class MediaListFragment : QuickActionDialogFragment()
{

    override fun getArrowImageViewId(): Int
    {
        return R.id.ivArrow
    }

    override fun getLayout(): Int
    {
        return R.layout.fragment_media_list
    }

    var rg: RadioGroup? = null
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View
    {
        val view = super.onCreateView(inflater, container, savedInstanceState)
        rg = view.findViewById(R.id.tab) as RadioGroup
        rg?.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId)
            {
                R.id.rbSelected -> childFragmentManager.beginTransaction().replace(R.id.pageContainer, MediaListPageFragment.newInstance(0)).commit()
                R.id.rbPlayed   -> childFragmentManager.beginTransaction().replace(R.id.pageContainer, MediaListPageFragment.newInstance(1)).commit()
            }
        }

        return view
    }

    override fun onActivityCreated(savedInstanceState: Bundle?)
    {
        super.onActivityCreated(savedInstanceState)
        rg?.check(R.id.rbSelected)
    }
}
